package com.r_z.controller;

import com.r_z.entity.Goods;
import com.r_z.entity.PurchasePlan;
import com.r_z.result.CommonResult;
import com.r_z.service.GoodsService;
import com.r_z.util.RequestMsg;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author 周楠櫻木
 * @version 1.0
 * @date 2023/6/4
 */

@RestController
@CrossOrigin
public class GoodsController {
    @Resource
    GoodsService goodsService;


    @RequestMapping("selectGoogs")
    public CommonResult LimitselectGoods(int page, int limit, @RequestParam(value = "strWhere", defaultValue = "") String strWhere) {
        int count = goodsService.countselectGoods(strWhere);
        List<Goods> goods = goodsService.LimitselectGoods(page, limit, strWhere);
        return RequestMsg.msg(count, goods);
    }


    @RequestMapping("selectPurchasePlan")
    public CommonResult selectPurchasePlan(int page, int limit, @RequestParam(value = "strWhere", defaultValue = "") String strWhere) {
        int count = goodsService.countPurchasePlan(strWhere);
        List<PurchasePlan> purchasePlans = goodsService.selectPurchasePlan(page, limit, strWhere);
        return RequestMsg.msg(count, purchasePlans);
    }

    @RequestMapping("insertPurchasePlan")
    public int insertPurchasePlan(@RequestBody PurchasePlan[] purchasePlan) {
        return goodsService.insertPurchasePlan(purchasePlan);

    }

    /**
     * 采购计划的删除方法
     * @param
     * @return 删除是否成功 boolean
     */
    @RequestMapping("deletePurchasePlan")
    public int deletePurchasePlan(@RequestBody PurchasePlan[] purchasePlans ){
        for (PurchasePlan purchasePlan : purchasePlans) {
            goodsService.deletePurchasePlan(purchasePlan.getGoodId());
        }
        return 0;
    }

    /**
     * 采购计划的删除方法
     * @param
     * @return 删除是否成功 boolean
     */
    @RequestMapping("deletePurchasePlan2")
    public int deletePurchasePlan2(int goodId){
        return goodsService.deletePurchasePlan(goodId);
    }

}
